<script type="text/javascript">
/* function back(destination){
 //alert(destination);
 window.location.assign(destination);
 } */

 function removeCollape(){
	//document.getElementById('popCmtLink').removeAttribute('href');
 }

 $(function ()  
		 {
		   $('.togger_hungdv7').popover(
		   {
		      trigger: 'hover',
		      html: true,     
		      content: 'hello world'
		   });
		 });
</script>


<div class="row"  style="margin-top: 20px">
	<div id="viewDetail">
		<div class="panel panel-default div-fixed">
			<div class="panel-heading">
				<div class="row">
					<div class="col-md-2 text-center"> 
						<img class="img-paperflip" src="/img/paperclip.png" />
		<p class="datetime-month datetime-view"><?php echo $d."/".$m;?></p>
					</div>

					<div class="col-md-7 text-left">
						<h1 class="text-custom" style="word-wrap:break-word;" >
							<?php  echo h($post['Post']['title']);?>
						</h1>
					</div>

					<div class="col-md-3 text-center">
						<div class="btn-group">
							<button type="button" class="btn btn-custom"
								onclick="window.location.assign('/posts/previousPost/<?php echo $post['Post']['id'];?>');">
								<span class="glyphicon glyphicon-chevron-left"></span>
							</button>
							<button type="button" class="btn btn-inverse"
								onclick="window.location.assign('<?php echo $backDestination;?>');">
								<span class="glyphicon glyphicon-home"></span>
							</button>
							<button type="button" class="btn btn-custom"
								onclick="window.location.assign('/posts/nextPost/<?php echo $post['Post']['id'];?>');">
								<span class="glyphicon glyphicon-chevron-right"></span>
							</button>
						</div>
					</div>
				</div>
			</div>
			<div class="panel-body">

				<div style="text-align: center;">
				<?php if($post['Post']['thumbnail']):?>
					<img src="<?php echo $post['Post']['thumbnail'];?>"
						class="img-thumbnail" style="max-height: 200px; max-width: 200px;">
						<?php endif;?>
						<br /> <br />
				</div>


				<?php echo $post['Post']['body']; ?>
			</div>
			<div class="panel-footer" style="height: 70px">
				<div class="col-xs-6">
					<blockquote>
						<small>Posted by: <?php echo $post['Post']['Username'];?> - at: <?php echo $post['Post']['created']; ?></small>
					</blockquote>
				</div>
				<div class="col-xs-6" align="right">
				<?php
				//if this user are author of this post -> show button edit,  - ThanhLD1
				if ($this->Session->check ( "AdminLogin" )) :
					$admin = $this->Session->read ( "AdminLogin" );
					if ($admin ['Admin'] ['AdminID'] == $post ['Post'] ['Admin_id']) :
						?>
				<div class="btn-group link-button">
						<a class="btn btn-custom" title="Edit this post!"
							href="/posts/edit/<?php echo $post['Post']['id']; ?>"><span
							class="glyphicon glyphicon-pencil"></span></a>
					</div>
				<?php endif;?>
				<?php endif;?>
				
				
			</div>
			</div>
		</div>
	</div>


	<!-- view comment -->
	<div class="row">
		<div class="col-md-8">
			<div class="panel-group" id="accordion">
				<div class="panel panel-default">
					<div class="panel-heading">
						<h4 class="panel-title">
							<span class="togger_hungdv7" data-container="body"
								data-toggle="popover" data-placement="right"
								data-content="View all comments"> <a data-toggle="collapse"
								data-parent="#accordion" href="#listComment"> <span
									class="badge"><?php echo $numOfCom; ?></span> Comment
							</a>
							</span>
						</h4>
					</div>
					<div id="listComment" class="panel-collapse collapse">
						<div class="panel-body">
					
						<?php foreach ($comments as $comment): ?>
						<div class="row comment">
								<div class="col-md-8">
									<h4> <?php echo $comment['Comment']['user']; ?> <small> said: <?php echo $comment['Comment']['content']; ?> </small>
									</h4>
								</div>
								<div class="col-sm-offset-8" >									
										<h6>At date <?php echo $comment['Comment']['created'];?></h6>									
								</div>

							</div>
<?php endforeach; ?>
<?php unset($comments);  ?>
					
					</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<!-- add comment -->
	<div class="row" id="openComment">
		<div class="col-md-9">
			<form method="post"
				action="/comments/add/<?php echo $post['Post']['id']; ?>"
				class="form-horizontal">

				<div class="form-group">
					<div class="col-md-10">
						<a id="popCmtLink" data-toggle="collapse"
							data-parent="#openComment" href="#openThis"> <textarea
								name="content" rows="4" cols="50" required="required"
								onkeypress="removeCollape();" placeholder="Your comment ~~~"
								class="form-control"></textarea>
						</a>
					</div>
				</div>
				<div id="openThis" class="panel-collapse collapse">
					<div class="form-group">
						<div class="col-md-10">
							<div class="input-group">
								<input type="text" name="user" required="required"
									placeholder="Your name" class="form-control"
									value="<?php if($this->Session->check('AdminLogin')) { $admin = $this->Session->read('AdminLogin'); echo $admin['Admin']['Fullname'];} ?>" />
								<span class="input-group-btn"><button type="submit"
										class="btn btn-warning">Add Comment</button></span>
							</div>
						</div>
					</div>
				</div>
				<!-- <div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="submit" class="btn btn-warning">Add Comment</button>
				</div>
			</div> -->
			</form>
		</div>
	</div>
</div>
<script>
// $('.myTab').click(function (e) {
// 	alert($(this).id);
// 	  e.preventDefault();
// 	  $(this).tab('show');
// 	});
</script>

